package com.api.shopapi.mapper;

import com.api.shopapi.entity.JKDanguchun;
import com.api.shopapi.entity.dto.JKDanguchunDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface JKDanguchunMapper {

    @Insert("insert into jk_danguchun (JKDanguchunCode,UserCode,DanGuChun,FromType,InspectTime,CreateTime) values " +
            "(#{jkDanguchun.JKDanguchunCode},#{jkDanguchun.UserCode},#{jkDanguchun.DanGuChun},#{jkDanguchun.FromType}," +
            "#{jkDanguchun.InspectTime},#{jkDanguchun.CreateTime})")
    int insert(@Param("jkDanguchun") JKDanguchun jkDanguchun);


    @Update("update jk_danguchun set UserCode=#{jkDanguchun.UserCode},DanGuChun=#{jkDanguchun.DanGuChun}," +
            "FromType=#{jkDanguchun.FromType},InspectTime=#{jkDanguchun.InspectTime},CreateTime=#{jkDanguchun.CreateTime} " +
            "where JKDanguchunCode=#{jkDanguchun.JKDanguchunCode}")
    int update(@Param("jkDanguchun") JKDanguchun jkDanguchun);

    @Delete("delete from jk_danguchun where JKDanguchunCode=#{jKDanguchunCode}")
    int delete(@Param("jKDanguchunCode") String jKDanguchunCode);

    @Select("select * from jk_danguchun where JKDanguchunCode=#{jKDanguchunCode} limit 1")
    JKDanguchun getByJKDanguchunCode(@Param("jKDanguchunCode") String jKDanguchunCode);

    @Select("select * from jk_danguchun where UserCode=#{userCode} and InspectTime between #{startTime} and #{endTime} order by InspectTime desc")
    List<JKDanguchun> getPageList(@Param("userCode") String userCode,@Param("startTime") String startTime,@Param("endTime") String endTime);


    @Select("<script>" +
            "select jd.*,u.Name as userName from jk_danguchun jd left join user u on jd.UserCode=u.UserCode " +
            "where u.GovernmentCode=#{governmentCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and u.Name like concat('%',#{name},'%') " +
            "</if>" +
            "and jd.InspectTime between #{startTime} and #{endTime} " +
            "order by jd.InspectTime desc" +
            "</script>")
    List<JKDanguchunDTO> getAdmPageList(@Param("name") String name, @Param("governmentCode") String governmentCode, @Param("startTime") String startTime, @Param("endTime") String endTime);

}
